<#assign renderStatus = false>
<#assign statusContent = ''>
<#if statistic.chartType??>
<script type="text/javascript" src="./../script/plugins/highchar/highcharts.js"></script>
<script type="text/javascript" src="./../script/plugins/highchar/modules/exporting.js"></script>
</#if>
<div class="west_all" style="padding:0px">&nbsp;</div>
<div class="center_all" style="padding:0px">
<div class="center" style="height:100%;padding:0px;">
    
    <div class="center_c" style="">	
    	<div class="center_c_n" style="background-image: url(./../theme/default/images/main/pane_top.png)"></div>
    	<div class="center_c_e" style="background-image: url(./../theme/default/images/main/pane_left.png)"></div>
        <div class="center_c_c">
        	<div class="center_c_c_n">
	            <div class="toolbar">
	                <ul class="program_toolbar" id="mainButton">
	                
	                    <#list common_func_list as comFunc>
	                        <#assign show="0">
	                        <#list feature_list as feature>
	                            <#if comFunc.function.name==feature.code>
	                                <#assign show="1">
	                            </#if>
	                        </#list>
	                        <#if show?? && show=="1">
	                            <#if comFunc.function.icon??>
	                                <li class="${comFunc.function.icon}" style="cursor:pointer" onclick="javascript:processCommonFunc('${comFunc.function.id}',<#if comFunc.isBatch??>'${comFunc.isBatch}'<#else>'0'</#if>,<#if comFunc.function.messageType??>'${comFunc.function.messageType}'<#else>'0'</#if>,<#if comFunc.function.message??>'${comFunc.function.message}'<#else>''</#if>,<#if comFunc.function.forwardType??>'${comFunc.function.forwardType}'<#else>''</#if>,<#if comFunc.function.clearSession??>'${comFunc.function.clearSession}'<#else>'0'</#if>);return false;"><a href="javascript:void(0)"><img src="./../theme/default/images/main/blank.gif" style="float:left;clear:left"><div style="line-height:20px;line-height:23px\9;float:left;cursor:pointer"><span style="cursor:pointer">${comFunc.function.displayName}</span></div></a></li>
	                            <#else>
	                                <li class="t8" style="cursor:pointer"><a href="javascript:void(0);"><img src="./../theme/default/images/main/blank.gif" onclick=""><br/></a></li>
	                            </#if>
	                     </#if>
	                    </#list>
	                </ul>
	            </div>
	       	</div>   
	       	<div class="center_c_c_c">  
	       		<div class="serverErrorContainer">
		            <div class="serverError">
		            <ol>

		            </ol>
		            </div>
		            <div class="container">
		                <div id="handleDiv" class="handleDiv" onclick="displayTable('handleDiv')"></div>
		                <div id="handleDiv_child" class="errorDIv" divAttend="attend">
		                    <ol>
		                    </ol>
		                </div>
		            </div>
		        </div> 
            	<table id="GridTable"></table>
	       	</div>
        </div><!--center_c_c-->
        <div class="center_c_w" style="background: url(./../theme/default/images/main/pane_right.png)"></div>
        <div class="center_c_s" style="background-image: url(./../theme/default/images/main/pane_bottom.png)"></div>
    </div>   <!--center_c-->
    
    
    
    <div class="center_s" style="">	
    	<div class="center_s_n" style="background-image: url(./../theme/default/images/main/pane_top.png)"></div>
    	<div class="center_s_e" style="background-image: url(./../theme/default/images/main/pane_left.png)"></div>
        <div class="center_s_c">
           
        
        	<#if statistic.chartType??>
            	<div id="container" style="width: 600px; height: 280px; margin: 0 auto"></div>
            </#if>
            
        </div>    
        <div class="center_s_w" style="background: url(./../theme/default/images/main/pane_right.png)"></div>
        <div class="center_s_s" style="background-image: url(./../theme/default/images/main/pane_bottom.png)"></div>
	</div>
   
</div><!--center-->
<form id="searchForm" onSubmit="return false">
<input type="hidden" id="businessProcessId" name="businessProcess.id" value="${businessProcess.id}">
<input type="hidden" id="statisticId" name="statistic.id" value="${statistic.id}">
<input type="hidden" id="id" name="id">
<input type="hidden" id="status" name="taskStatus">
<input type="hidden" id="functionId" name="function.id" value="${function.id}">
<#if !statistic.isTree?? || statistic.isTree == "0">
<div class="west" style="height:100%;">
            <div class="west_n" style="background-image: url(./../theme/default/images/main/pane_top.png)"></div>
            <div class="west_e" style="background-image: url(./../theme/default/images/main/pane_left.png)"></div>
            
            <div class="west_c">
               <!--  <div class="west_c_c"> -->
                	<!-- <div class="west_c_c_n">-->
                        <div style="background:#9DDAEC; text-align:center; height:20px; width:100%; float:left;">查询</div>
                    <!-- </div>-->
                    
                    <!-- <div class="west_c_c_c">-->
                        <div id="queryForm" style="float:left; width:100%;">        
                            
                            <#list query_field_list as queryField>
                                <#if queryField.hidden?? && queryField.hidden=="1">
                                    ${queryField.content}
                                <#else>
                                <#if  queryField.type?? &&queryField.type != "3">
	                                <table>
	                                    <tr>
	                                        <td class="textColor">
	                                        ${queryField.field.displayName?default(queryField.field.desc)}:
	                                        </td>
	                                    </tr>
	                                    <tr>
	                                        <td class="elementColor">
	                                        ${queryField.content}
	                                        </td>
	                                    </tr>
	                                </table>
                                <#else>
                                	<#assign renderStatus = true>
                                	<#assign statusContent = queryField.content>
                                </#if>
                                </#if>
                            </#list>
                            
                        	<div class="buttonBox"><a href="#" class="button" tabindex="-1"><input id="search" type="button" value="查询" onClick=""></a></div>
                        </div>
            </div>
            <div class="west_w" style="background: url(./../theme/default/images/main/pane_right.png)"></div>
            <div class="west_s" style="background-image: url(./../theme/default/images/main/pane_bottom.png)"></div>
            </div>
</div>
</div>
</#if>
 </form>
<script language="javascript">
var chart;
var chartData;
$(function(){
    layout();
    loadGrid();
    <#if statistic.chartType??>
    loadChart();
    </#if>
    <#if !statistic.isTree?? || statistic.isTree == "0">
    $('#search').click(function(){
          $('#GridTable').datagrid("options").url=TDQS.CONTEXT_PATH+'business/statistic.action?tdqssid='+TDQS.SESSION_ID;
          $('#GridTable').datagrid("tdqsLoad",getFormParams('searchForm'));
          loadChart();
        });
    document.getElementsByTagName('form')[0].onkeydown = function(e){
          var e = e || event;
          var keyNum = e.which || e.keyCode;
          if(keyNum==13){
              $('#search').click();
              return false;
          }
          return true;
        };
     </#if>
});
function loadGrid(){
	 <#if !statistic.isTree?? || statistic.isTree == "0">
     ${"$('#GridTable')"}.datagrid({            
            url:TDQS.CONTEXT_PATH+'business/statistic.action?ajaxLoadType=1&tdqssid='+TDQS.SESSION_ID,
            queryParams:getFormParams('searchForm'),
            idField:"id",
            pagination:false,
            frozenColumns:[[
                <#assign index=0>
                <#list dimension_list as dimen>
                <#if !dimen.isShow?? || dimen.isShow=="1">
                <#if index gt 0>
                ,
                </#if>
                {
                 field : '${dimen.field.name}',
                 title : '${dimen.name}',
                 width : ${dimen.width?default(200)},
                 editor : 'text',
                 defaultValue : '',
                 align : 'center',
                 edit : true,
                 formatter:function(value, row, index){
                     var fieldValue = '';
                     if(row && row.fieldMap && row.fieldMap['${dimen.field.name}']) {
                         fieldValue = row.fieldMap['${dimen.field.name}'].value;
                     }
                     return fieldValue;
                 }
                }
                <#assign index=index+1>
                </#if>
                </#list>
                ] ],
       <#else>
       $('#GridTable').treegrid({
				width:700,
				height:350,
				collapsible:true,
				nowrap: false,
				rownumbers: true,
				singleSelect:true,
				url:TDQS.CONTEXT_PATH+'business/statistic.action?tdqssid='+TDQS.SESSION_ID,
				queryParams:getFormParams('searchForm'),
				idField:'id',
				treeField:'id',
            frozenColumns:[[
            	<#assign index=0>
                <#list dimension_list as dimen>
                <#if !dimen.isShow?? || dimen.isShow=="1">
                <#if index gt 0>
                ,
                </#if>
                {
                 field : '${dimen.field.name}',
                 title : '${dimen.name}',
                 width : ${dimen.width?default(200)},
                 editor : 'text',
                 defaultValue : '',
                 align : 'center',
                 edit : true,
                 formatter:function(value, row, index){
                     var fieldValue = '';
                     if(row && row.fieldMap && row.fieldMap['${dimen.field.name}']) {
                         fieldValue = row.fieldMap['${dimen.field.name}'].value;
                     }
                     return fieldValue;
                 }
                }
                <#assign index=index+1>
                </#if>
                </#list>
                ] ],
       </#if>
            columns:[ [ 
                <#assign index=0>
                <#list item_list as item>
                <#if index gt 0>
                ,
                </#if>
                {
                     field : '<#if item.field?? && item.field.name??>${item.field.name}<#else>${item.statisticMethod}</#if>',
                     title : '${item.name}',
                     width : ${item.width?default(200)},
                     editor : 'text',
                     defaultValue : '',
                     align : 'center',
                     edit : true,
                     sortable : false,
                     formatter:function(value, row, index){
                         var fieldValue = '';
                     <#if item.field?? && item.field.name??>
                     if(row && row.fieldMap && row.fieldMap['${item.statisticMethod}(${item.field.name})']) {
                         fieldValue = row.fieldMap['${item.statisticMethod}(${item.field.name})'].value;
                     }
                     <#else>
                     if(row && row.fieldMap && row.fieldMap['${item.statisticMethod}']) {
                         fieldValue = row.fieldMap['${item.statisticMethod}'].value;
                     }
                     </#if>
                     return fieldValue;
                     }
                }
                <#assign index=index+1>
                </#list>
                <#if statistic.allowOperColumn?? && statistic.allowOperColumn=="1">
                ,            
                 {    
                    field : 'opt',
                    title : '操作',
                    width : 280,
                    align : 'center',
                    rowspan : 2,
                    formatter:function(value, row, index){
                        var opers = '';
                        if(row && row.listFunctionList) {
                            for(var i=0,l=row.listFunctionList.length;i<l;i++) {
                                 var func = row.listFunctionList[i];
                                 var funcId = '';
                                 var messageType = '';
                                 var message = '';
                                 var funcName = '';
                                 var forwardType = '';
                                 var clearSession = '';
                                 if(func) {
                                     if(func.id) {
                                         funcId = func.id;
                                     }
                                     if(func.messageType) {
                                         messageType = func.messageType;
                                     }
                                     if(func.message) {
                                         message = func.message;
                                     }
                                     if(func.displayName) {
                                         funcName = func.displayName;
                                     }
                                     else if(func.desc) {
                                         funcName = func.desc;
                                     }
                                     if(func.forwardType) {
                                         forwardType = func.forwardType;
                                     }
                                     if(func.clearSession) {
                                         clearSession = func.clearSession;
                                     }
                                 }
                                 if(!row.editStatusFunction || row.editStatusFunction.id !== func.id) {
                                 	opers += "<a href=\"javascript:void(0)\" onclick=\"javascript:processRowFunc('"+row.id+"','"+funcId+"','"+row.index+"','"+messageType+"','"+message+"','"+forwardType+"','"+clearSession+"');return false;\">"+funcName+"</a>";
                                 	opers += "&nbsp;&nbsp;";
                                 }
                            }
                        }
                        if(opers=='') {
                             opers = '&nbsp;';
                        }
                        return opers; 
                    }
                }
                </#if>
                ] ],
            operations:{}
            ,
       		onLoadSuccess: function(row)
			{				       
					 resizeDatagrid();
					 <#if !statistic.isTree?? || statistic.isTree == "0">
					 <#if statistic.isMergeCell?? && statistic.isMergeCell == "1">
					 mergeFirstColumnCell();
					 </#if>
            <#else>
					 $('#GridTable').treegrid('collapseAll');
					 </#if>
			}
            
        });
            
}

function mergeFirstColumnCell() {
	var rows = $('#GridTable').datagrid("getData").rows;
	<#if dimension_list?? && dimension_list?size gt 0>
	var i=0;
	if(rows.length==0 || !rows[0] || !rows[0].fieldMap || !rows[0].fieldMap['${dimension_list[0].field.name}']) {
		return false;
	}
	while(i<rows.length) {
		if(rows[i] && rows[i].fieldMap && rows[i].fieldMap['${dimension_list[0].field.name}']) {
			var value = rows[i].fieldMap['${dimension_list[0].field.name}'].value;
			if(i<rows.length-1) {
				var j = i+1;
				while(j<rows.length) {
					if(rows[j] && rows[j].fieldMap && rows[j].fieldMap['${dimension_list[0].field.name}']) {
						var nextValue = rows[j].fieldMap['${dimension_list[0].field.name}'].value;
						if(value!=nextValue) {
							break;
						} else {
							j++;
						}
					} else {
						break;
					}
				}
				if(j>i+1) {
					$('#GridTable').datagrid('mergeCells',{
	            index:i,
	            field:'${dimension_list[0].field.name}',
	            rowspan:(j-i)
	        });
	        i=j-1;
				}
			}
		}
		i++;
	}
	</#if>
}

function loadChart(){
	$.tdqsAjax({
		type: "post",
		dataType: "json",
		url: TDQS.CONTEXT_PATH+"business/chart.action?tdqssid="+TDQS.SESSION_ID,
		data: $('#searchForm').serialize(),
		success:function(json) {
			if(json.data) {
				chartData = eval('('+json.data+')');
				chart = new Highcharts.Chart(chartData);
			}
		}
	});
}

function process(funcId,messageType,message,forwardType,clearSession,row) {
      ${"$('#functionId')"}.val(funcId);
      var url = TDQS.CONTEXT_PATH+'business/process?tdqssid='+TDQS.SESSION_ID+ "&function.id="+${"$('#functionId')"}.val()+"&businessProcess.id="+${"$('#businessProcessId')"}.val()+"&statistic.id="+$('#statisticId').val();
      if($('#id').val()!='') {
          url += ("&id="+$('#id').val());
      }
      if('1'==clearSession) {
      	url += "&clearSession=true";
      }
      if(row) {
      	if(row.fieldMap) {
      		for(var i=0;i<row.fieldMap.length;i++) {
      			var col = row.fieldMap[i];
		      	if(col && col.field && col.field.id && col.field.name) {
		      		url  += ('&paramsMap["'+col.field.name+'"].field.id='+col.field.id);
		      		url  += ('&paramsMap["'+col.field.name+'"].value='+col.value);
		      		url  += ('&paramsMap["'+col.field.name+'"].entityId='+col.entityId);
		      	}
	      	}
      	}
      }
      url += "&date="+new Date().toLocaleString();
      if(!message||message=='') {
            message = '确定要执行操作吗？';
      }
      if(messageType && messageType=='1') {
          jConfirm(message, '确认对话框 ', function(r) {
                        if(r){
                            if(forwardType && forwardType=='2') {
                                executeAjaxFunction(url);
                            }
                            else {
                                document.location.href = url;
                            }
                        }else{
                            return false;
                        }
          });
      }
      else {
            if(forwardType && forwardType=='2') {
                executeAjaxFunction(url);    
            }
            else {
                document.location.href = url;
            }
      }
}
function executeAjaxFunction(url) {
    $.tdqsAjax({
        type: "post",
        dataType: "json",
        url: url,
        success:function(json) {
            if(json.data && json.data.type && json.data.type=='2' && json.data.resultData){
                jAlert(json.data.resultData,'提示',function(){
                	<#if !statistic.isTree?? || statistic.isTree == "0">
                    $('#GridTable').datagrid("tdqsReload");
                    <#else>
                    $('#GridTable').treegrid("tdqsReload");
                    </#if>
                });
            }
            else {
           		<#if !statistic.isTree?? || statistic.isTree == "0">
                $('#GridTable').datagrid("tdqsReload");
                <#else>
                $('#GridTable').treegrid("tdqsReload");
                </#if>
            }
            ${"$('#id')"}.val('');
            $('#GridTable').datagrid('clearSelections');
            $('input','.datagrid-header-check').each(function(){
                $(this).removeAttr("checked");
            });
        }
    });
}
function processRowFunc(id,funcId,index,messageType,message,forwardType,clearSession) {
     $('#id').val(id);
     var row = $('#GridTable').datagrid("getRows")[index];
     process(funcId,messageType,message,forwardType,clearSession,row);
}

function processCommonFunc(funcId,isBatch,messageType,message,forwardType,clearSession) {
   if(isBatch && isBatch=='1') {
          var select = $('#GridTable').datagrid('getSelections');
          var primaryValue = "";
          var status = "";
          if (select && select != "") {
              for ( var i = 0; i < select.length; i++) {
                  if (i < select.length - 1) {
                       primaryValue += select[i].id+ ",";
                       if(select[i].status && select[i].status.id) {
                       		status += select[i].status.id+ ",";
                       }
                                
                   } else {
                        primaryValue += select[i].id;
                        if(select[i].status && select[i].status.id) {
                       		status += select[i].status.id;
                       }
                   }
               }
           }
           if(!primaryValue || primaryValue=='') {
              jAlert('请选择${businessProcess.businessObj.desc}！','提示',function(){});
              return false;
           }
        $('#id').val(primaryValue);
        $('#status').val(status);
    }
    process(funcId,messageType,message,forwardType,clearSession);
}

var mainLayout;
var centerContentLayout;
var contentLayout;
function layout(){
        var toggle_we        = '<div class="btnToggler_we"></div>'
        , toggle_w            = '<div class="btnToggler_w"></div>'
        , btnToggler_se        = '<div class="btnToggler_se"></div>'
        , btnToggler_s        = '<div class="btnToggler_s"></div>'
        
        $('body').layout({
            defaults:{
                onresize_end:    resizeDatagrid
                ,onclose_end:    resizeDatagrid  
            }
            ,center:{
                paneSelector:    ".center_all" 
            }
            ,west:{
                     size:    10
                ,    paneSelector:    ".west_all" 
                ,    spacing_open:    0
                ,    spacing_closed:   0        
                ,    togglerLength_closed:        0
                ,    togglerLength_open:       0
            }
        });

        $('.center_all').layout({
            defaults:{
                onresize_end:    resizeDatagrid
                ,onclose_end:    resizeDatagrid  
            }
            ,center:{
                paneSelector:    ".center" 
            }
            ,west:{
                     size:    250
                ,    paneSelector:    ".west" 
                ,    spacing_open:    3
                ,    spacing_closed:    3        
                ,    togglerLength_closed:        24
                ,    togglerLength_open:        24
                ,    togglerContent_closed:    toggle_w
                ,    togglerContent_open:    toggle_we
                ,    resizable:    false
            }
        });
        
        $('div.center').layout({
        	defaults:{
                onresize_end:    resizeDatagrid
                ,onclose_end:    resizeDatagrid  
            }
        	,center:{
                paneSelector:    ".center_c" 
            }  
            ,south:{
                    paneSelector:    ".center_s"
                ,   size:	300
				,	spacing_open:	3
				,	spacing_closed:	3			
				,	togglerLength_closed:		24
				,	togglerLength_open:		24
				,	togglerContent_closed:	btnToggler_s
				,	togglerContent_open:	btnToggler_se  
				,    resizable:    false       
            } 
        
        });

        $('div.center_c').layout({
             center__paneSelector:    ".center_c_c" 
        ,    north__size:    3
        ,    north__paneSelector:    ".center_c_n" 
        ,    north__spacing_open:    0
        ,    north__spacing_closed:    0        
        ,    south__paneSelector:    ".center_c_s"
        ,    south__size:    3
        ,    south__maxSize:            3
        ,    south__spacing_open:    0
        ,    south__spacing_close:    0
        ,    south__closable:        false
        ,    south__resizable:        false
        ,    east__size:    3
        ,    east__paneSelector:    ".center_c_e" 
        ,    east__spacing_open:    0
        ,    east__spacing_closed:    0        
        ,    west__size:    3
        ,    west__paneSelector:    ".center_c_w" 
        ,    west__spacing_open:    0
        ,    west__spacing_closed:    0    
        });
        $(".center_c_n,.center_c_s,.center_c_e,.center_c_w").css({overflow:"hidden"});

        $('div.center_c_c').layout({
            center:{
                paneSelector:    ".center_c_c_c" 
            }
            ,north:{
                     paneSelector:    ".center_c_c_n"
                ,    size:    30
                ,    spacing_open:    0
                ,    spacing_closed:    0            
            } 
         });
        $(".center_c_c_n").css({overflow:"hidden"});
         
         $('div.center_s').layout({
             center__paneSelector:    ".center_s_c" 
        ,    north__size:    3
        ,    north__paneSelector:    ".center_s_n" 
        ,    north__spacing_open:    0
        ,    north__spacing_closed:    0        
        ,    south__paneSelector:    ".center_s_s"
        ,    south__size:    3
        ,    south__maxSize:            3
        ,    south__spacing_open:    0
        ,    south__spacing_close:    0
        ,    south__closable:        false
        ,    south__resizable:        false
        ,    east__size:    3
        ,    east__paneSelector:    ".center_s_e" 
        ,    east__spacing_open:    0
        ,    east__spacing_closed:    0        
        ,    west__size:    3
        ,    west__paneSelector:    ".center_s_w" 
        ,    west__spacing_open:    0
        ,    west__spacing_closed:    0    
        });
        $(".center_s_n,.center_s_s,.center_s_e,.center_s_w").css({overflow:"hidden"});

        <#if !statistic.isTree?? || statistic.isTree == "0">
        $('div.west').layout({
            center__paneSelector:    ".west_c" 
        ,   north__size:    3
        ,    north__paneSelector:    ".west_n" 
        ,    north__spacing_open:    0
        ,    north__spacing_closed:    0        
        ,   south__paneSelector:    ".west_s"
        ,    south__size:    3
        ,    south__maxSize:            3
        ,    south__spacing_open:    0
        ,    south__spacing_close:    0
        ,    south__closable:        false
        ,    south__resizable:        false
        ,   east__size:    3
        ,    east__paneSelector:    ".west_e" 
        ,    east__spacing_open:    0
        ,    east__spacing_closed:    0        
        ,   west__size:    3
        ,    west__paneSelector:    ".west_w" 
        ,    west__spacing_open:    0
        ,    west__spacing_closed:    0    
        });
        $(".west_s,.west_n,.west_e,.west_w").css({overflow:"hidden"});
        /*
        $('div.west_c').layout({
            <#if  renderStatus>
            south:{
                paneSelector:    ".west_c_s" 
            },
            </#if>
            center:{
                    paneSelector:    ".west_c_c"
                ,   size:    300
                ,    spacing_open:    0
                ,    spacing_closed:    0            
                ,    togglerLength_closed:        0
                ,    togglerLength_open:        0
            } 
         });
         */
        
        /*
        <#if  renderStatus>
        $('div.west_c_s').layout({   
            center:{
                paneSelector:    ".west_c_s_c" 
            }
            ,north:{
                    paneSelector:    ".west_c_s_n"
                ,   size:    20
                ,    spacing_open:    0
                ,    spacing_closed:    0            
                ,    togglerLength_closed:        0
                ,    togglerLength_open:        0
            }    
        });
        </#if>
        */
        
        /*
        $('div.west_c_c').layout({   
            center:{
                paneSelector:    ".west_c_c_c" 
            }
            ,north:{
                    paneSelector:    ".west_c_c_n"
                ,   size:    20
                ,    spacing_open:    0
                ,    spacing_closed:    0            
                ,    togglerLength_closed:        0
                ,    togglerLength_open:        0
            }    
        }); 
        */
        </#if>
}
$(window).resize(function(){resizeDatagrid();})
function resizeDatagrid(){
    $('#GridTable').datagrid("autoresize",{rh:310});
}
</script>                                                                                                                                                                                                                                                                                       